package com.coocaa.ops.admin.v1.cornericontype;

import com.coocaa.ops.admin.base.annotation.Auth;
import com.coocaa.ops.admin.base.annotation.Config;
import com.coocaa.ops.admin.base.controller.MgrBaseController;
import com.coocaa.ops.admin.base.util.WebUtil;
import com.coocaa.ops.admin.base.validator.InputParamsValidator;
import com.coocaa.ops.admin.v1.cornericon.validator.CornerIconValidator;
import com.coocaa.ops.admin.v1.cornericontype.model.GlobalCornerIconTypeModel;
import com.coocaa.ops.admin.v1.cornericontype.service.ICornerIconTypeService;
import com.coocaa.ops.admin.v1.cornericontype.validator.CornerIconTypeValidator;
import com.coocaa.ops.common.core.base.enums.AuthEnum;
import com.coocaa.ops.common.core.base.model.R;
import com.coocaa.ops.common.core.biz.cornericontype.entity.GlobalCornerIconTypeEntity;
import com.coocaa.ops.common.tool.json.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author bijiahao
 * @date : 2019/3/21.
 * @description
 */
@RestController
/**
 * 菜单elid
 */
@Config(menuToken = "cornerIconType")
@RequestMapping("/v1/cornerIconType")
public class CornerIconTypeController extends MgrBaseController {
    @Autowired
    private ICornerIconTypeService cornerIconTypeService;

    /**
     * 获取所有有效的角标分类
     *
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/getCornerTypes", method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
    public Object getCornerTypes() {
        Map result = cornerIconTypeService.getCornerTypes();
        return render2Json(result);
    }


    /**
     * 保存
     *
     * @param request
     * @param jsonStr
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.SAVE)
    @RequestMapping(value = "/save", produces = "text/html;charset=UTF-8")
    public Object save(HttpServletRequest request, String jsonStr) {
        GlobalCornerIconTypeEntity entity = (GlobalCornerIconTypeEntity) JsonUtil.json2Object(jsonStr, GlobalCornerIconTypeEntity.class);
        CornerIconTypeValidator.valid(entity);
        cornerIconTypeService.save(entity, WebUtil.getCurrentUser(request));
        return R.ok();
    }

    /**
     * 获取详情信息
     *
     * @param id
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/getDetailInfo",method = RequestMethod.GET)
    public Object getDetailInfo(Integer id) {
        InputParamsValidator.validIdValue(id);
        GlobalCornerIconTypeEntity entity = cornerIconTypeService.getDetailInfo(id);
        Map result = R.ok(entity);
        return render2Json(result);
    }


    /**
     * 分页数据
     *
     * @param request
     * @param model
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/pageList",method = {RequestMethod.GET,RequestMethod.POST})
    public Object pageList(HttpServletRequest request, GlobalCornerIconTypeModel model) {
        Map<String, Object> data = cornerIconTypeService.getPageResult(model);
        return render2Json(data);
    }

    /**
     * 删除记录
     *
     * @param
     * @param request
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.DELETE)
    @RequestMapping(value = "/remove",method = {RequestMethod.GET,RequestMethod.POST})
    public Object remove(Integer[] id, HttpServletRequest request) {
        return cornerIconTypeService.deleteBatch(id, WebUtil.getCurrentUser(request));
    }

    @Auth(verifyAuthority = true, authorityType = AuthEnum.EDIT)
    @RequestMapping(value = "/updatePriority",method = {RequestMethod.GET,RequestMethod.POST}, produces = "text/html;charset=UTF-8")
    public Object updatePriority(HttpServletRequest request, @RequestParam Integer priority, @RequestParam Integer typeId) throws Exception {
        //修改优先级
        cornerIconTypeService.updatePriority(typeId, priority, WebUtil.getCurrentUserId(request));
        return R.ok().msg("修改优先级成功");
    }

    /**
     * 获取菜单运行权限列表
     *
     * @param request
     * @param
     * @return
     */
    @Auth(verifyAuthority = true, authorityType = AuthEnum.BROWSER)
    @RequestMapping(value = "/getMenuInfo",method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
    public Object getMenuInfo(HttpServletRequest request) {
        Map result = getMenuInfo(this.getClass(), request);
        return render2Json(result);
    }
}
